package com.rr.graphql.context;

import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.context.DgsCustomContextBuilderWithRequest;
import graphql.GraphQL;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequest;

import java.util.Map;

/**
 * @author RR
 * @date 2023/7/1 13:57
 */
@Component
@Slf4j
public class MyCustomContextBuilder implements DgsCustomContextBuilderWithRequest<MyCustomContext> {
    
    @Override
    public MyCustomContext build(@Nullable Map<String, ?> map, @Nullable HttpHeaders httpHeaders, @Nullable WebRequest webRequest) {
        log.info("构造自定义上下文");
        MyCustomContext myCustomContext = new MyCustomContext();
        myCustomContext.setTimestamp(System.currentTimeMillis());
        return myCustomContext;
    }

}
